package demo1;

import com.sun.source.tree.Tree;

public class BinaryTree {
    static class TreeNode{
        public char val;
        public TreeNode left;
        public TreeNode right;
        public TreeNode(char val){
            this.val = val;
        }
    }
    public TreeNode root;
    public TreeNode creatTree(){
        TreeNode A = new TreeNode('A');
        TreeNode B = new TreeNode('B');
        TreeNode C = new TreeNode('C');
        TreeNode D = new TreeNode('D');
        TreeNode E = new TreeNode('E');
        TreeNode F = new TreeNode('F');
        TreeNode G = new TreeNode('G');
        TreeNode H = new TreeNode('H');
        A.left = B;
        A.right = C;
        B.left = D;
        B.right = E;
        E.right = H;
        C.left = F;
        C.right = G;
        return A;
    }
    public void preOrder(TreeNode root){
        if(root == null){
            return;
        }
        System.out.print(root.val + " ");
        preOrder(root.left);
        preOrder(root.right);
    }
    public void inOrder(TreeNode root){
        if(root == null){
            return ;
        }
        inOrder(root.left);
        System.out.print(root.val + " ");
        inOrder(root.right);
    }
    public void postOrder(TreeNode root){
        if(root == null){
            return ;
        }
        postOrder(root.left);
        postOrder(root.right);
        System.out.print(root.val + " ");
    }
    public static int NodeCount = 0;
    public void size(TreeNode root){
        if(root == null){
            return;
        }
        NodeCount++;
        size(root.left);
        size(root.right);
    }
    public int nodeSize(TreeNode root){
        if(root == null){
            return 0;
        }
        return nodeSize(root.left) + nodeSize(root.right) + 1;
    }
    public static int leafCount = 0;
    public void getLeafCount(TreeNode root){
        if(root == null){
            return;
        }
        if(root.left == null && root.right == null){
            leafCount++;
        }
        getLeafCount(root.left);
        getLeafCount(root.right);
    }
    public int getLeveNodeCount(TreeNode root,int k){
        if(root == null){
            return 0;
        }
        if(k == 1){
            return 1;
        }
        return getLeveNodeCount(root.left, k-1) +
        getLeveNodeCount(root.right,k-1);
    }
}
